/*
简单工厂模式是由一个工厂对象决定创建出哪一种产品类的实例

缺点:
如果产品的种类非常多switch case的判断会变得非常多
不符合开放—封闭原则,如果要增加或删除一个产品种类,就要修改switch case的判断代码
*/
abstract class Coffee {
  constructor(public name: string){

  }
}

class AmericanCoffee extends Coffee{
}

class LatteCoffee extends Coffee{
}

class CappuccinoCoffee extends Coffee{
}

class CafeFactory {
  static order(name: string){
    switch (name) {
    case 'AmericanCoffee':
      return new AmericanCoffee('美式咖啡')
    case 'LatteCoffee':
      return new LatteCoffee('拿铁咖啡')
    case 'CappuccinoCoffee':
      return new CappuccinoCoffee('卡布奇诺咖啡')
    default:
      throw new Error('你点的咖啡品种我们不支持')
    }
  }
}

console.log(CafeFactory.order('AmericanCoffee'))
console.log(CafeFactory.order('LatteCoffee'))
console.log(CafeFactory.order('CappuccinoCoffee'))
